define(['app'],function(app) {
	return {module: function($scope, $http, eventBusService, httpService, params, configService) {
		$scope.form = {};
        $scope.form.fk_textbook = params.fk_textbook;
        $scope.form.node_pid = '0';

        httpService.post(app.urls.chapter_getMaxCode, $scope.form, function(data) {
            if(data.code == "0000") {
                if(data.data == '1') {
                    $scope.form.code = $scope.form.fk_textbook + '01';
                }else{
                    $scope.form.code = data.data;
                }
            }else{
                eventBusService.publish("modal.alert", {"content":data.msg});
            }
        });

    	//保存
    	$scope.save = function() {
    		if(!$scope.formCheck()) {
                return;
            }

            $scope.form.node_isleaf = '1';
            $scope.form.node_type = '1';
			httpService.post(app.urls.chapter_insert, $scope.form, function(data) {
    			if(data.code == "0000") {
    			     eventBusService.publish("modal.page.close",{});
                     eventBusService.publish("content.page.reload", data.data);
    			}else{
    				eventBusService.publish("modal.alert", {"content":data.msg});
    			}
            });
        };
	}
}});
